<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>检查图片的大小</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>
  
  <body>
    <input type="text" size="4" value="10" name="fileSizeLimit"	id="fileSizeLimit" />
K
<input type="file" name="file1" id="file1" size="40"
	onchange="changeSrc(this)" />
<br>
<img src=http://blog.xunuo.com/blog/images/icons/23.gif id="fileChecker" alt="test" />
<script type="text/javascript">
var oFileChecker = document.getElementById("fileChecker");
function changeSrc(filePicker)
{
    oFileChecker.src = filePicker.value;
}
oFileChecker.onreadystatechange = function ()
{
    if (oFileChecker.readyState == "complete")
    {
        checkSize();
    }
}

function checkSize()
{
    var limit  = document.getElementById("fileSizeLimit").value * 1024;
    if (oFileChecker.fileSize > limit)
    {
        alert("too large");
    }
    else
    {
        alert("ok");
    }
    var srcValue = document.getElementById("file1").value.toLowerCase();
    if(!/(.jpg$)|(.bmp$)|(.png$)|(.gif$)/.test(srcValue)){
    	alert("格式错误");
    }
}
</script>

  </body>
</html>
